home *** CD-ROM | disk | FTP | other *** search
- Path: news.kei.com!ub!newserve!rebecca!rpi!not-for-mail
- From: Bowden Wise <wiseb@cs.rpi.edu>
- Newsgroups: comp.lang.c++.moderated,comp.lang.c++
- Subject: Singleton Registry Revisited
- Date: 19 Jan 1996 22:55:53 -0000
- Organization: Rensselaer Polytechnic Institute, Computer Science
- Sender: cppmods@netlab.cs.rpi.edu
- Approved: vandevod@cs.rpi.edu
- Message-ID: <4dp7hp$egd@netlab.cs.rpi.edu>
- NNTP-Posting-Host: netlab.cs.rpi.edu
- X-Original-Date: Fri, 19 Jan 1996 17:35:30 -0800
-
- Thanks to those of you who responded to my query about a hierarchy
- of Singletons. Recall, that my plan is to have a hierarchy of
- Singletons.
-
- All of the singletons share some base functionality, which I have
- placed in a base class: BaseResource ... this class is also
- abstract, so I can only use BaseResource's as pointers and references.
-
- Say we have two resources, derived from that one,
- class Resource1 : public BaseResource;
- class Resource2 : public BaseResource;
-
- I have placed the singleton code in a template class, so that I
- can instantiate singleton instances of resources like this:
-
- static Singleton<Resource1> singletonResource1;
- static Singleton<Resource2> singletonResource2;
-
- This all works great.
-
- Now, the problem at hand is to implement a SingletonRegistry.
- However, I believe I cannot do this since I have separated the
- singleton functionality from the base class functionality. It
- appears to me that I must not use a template to separate the
- singleton functionality from the BaseResource class. Since
- the way it is set up now, there is no way to create a map from
- resource names -> resource instances
-
- I am going in circles here trying to figure out what I need, here
- is some of my ramblings ...
-
- I plan to use the STL map container, and was trying to develop my
- map entries:
-
- typedef map < string, Singleton<BaseResource&>* > MyMap;
-
- but I dont think this will work, since the above Singletons
- are not derived from a Singleton<BaseResource>
-
- Maybe what I need instead is to make the singletons like this:
-
- typedef map < string, Singleton<BaseResource*>* > MyMap
-
- and then
-
- when a concrete singleton resource is created, such as the,
- Singleton<Resource1> have it register itself like this in the
- constructor perhaps:
-
- Singleton<Resource1>::Singleton<Resource1>
- {
- // but I cannot access the base part of Resource1 from here ??
- // so no way to call
- // this is not what we want since it is not derived from
- // Singleton<BaseaResource*>
- registry.Register ("Resource1", this );
- }
-
- Any ideas anyone? I'll keep thinking ...
- Bowden
-
- --------------------------------------------------------------------
- G. Bowden Wise
- Computer Science Dept, Rensselaer Polytechnic Inst, Troy, NY 12180
- Email: wiseb@cs.rpi.edu WWW: http://www.cs.rpi.edu/~wiseb/
-
- [ Articles to moderate: mailto:c++-submit@netlab.cs.rpi.edu ]
- [ Read the C++ FAQ: http://www.connobj.com/cpp/cppfaq.htm ]
- [ Moderation policy: http://www.connobj.com/cpp/guide.htm ]
- [ Comments? mailto:c++-request@netlab.cs.rpi.edu ]
-